import java.util.*;
import java.io.*;

public class CompilationStack extends java.util.Stack<String>{
	
	Vector hardList = new Vector();
	
	public String pushImportString(String importName){		
		//al momento gestisco solo import del tipo A.*; dove A è una cartella.
		
		
		if (!importName.endsWith("*")) return null;
		char sysSlash  = System.getProperty("file.separator").charAt(0);
		
		importName = importName.substring(0,importName.length()-".*".length());
		String fileName =  importName.replace('.',sysSlash);
		File dir  = new File(fileName);
		if (dir.isDirectory()){
				pushDir(dir);
				return dir.getName();			
		}		
		else return null;		
		
			
	}
	
	public String push(String fileName){
		if (hardList.contains(fileName)) return null;
		hardList.add(fileName);
		return super.push(fileName);
	}
	
	public void pushDir(String fileName){
		File file = new File(fileName);
		File dir = file.getParentFile();
		if(dir.isDirectory()){
			pushDir(dir);
		}
	}
		
	private void pushDir(File dir){
		String[] files = dir.list();
		for(int i =0;i<files.length;i++){
			
			if (files[i].endsWith(".pj")){
				
				if(push(dir.getPath()+dir.separator+files[i])!=null){
					
				}
			}
		}	
	}
		
	
	public CompilationStack(){
		super();
	}
	
	
	
	
	
	
}
